module.exports = function ($resource, $state, $http, $q, FileUploader, toaster, $modal,$stateParams) {
  
	return {

		restrict: 'AE',
		template: require('../views/reviewedlist.html'),
		replace: true,
		scope: {
			'saleobj': '=',
			'funobj': '=',
			'baseinfo': '=',
			'util': '=',
			'reviewflag' : '=',
		},
		link: function (scope, elements, attrs) {
      scope.type = $stateParams.type;
      console.log(scope.type);
      scope.flag = {
        'planning_state' : '1',
        'project_state' : '5'
      }
      var params = {};
      if(scope.type == '0'){ // 区县(规划处)
        url = '/api/as/ggc/reviewPlanning/findInfoList';
        params = {
          'city_project' : '0',
          'planning_state' : '1',
          // 'project_state' : '5'
        }
      } else if(scope.type == "1"){ // 本级
        url = '/api/as/ggc/reviewPlanning/findInfoList';
        params = {
          'city_project' : '1',
          'planning_state' : '1',
          // 'project_state' : '5'
        }
      } else if(scope.type == "3"){ // 区县(责任处室)
        url = '/api/as/ggc/reviewCityResponsible/approvalList';
        params = {
          'city_project' : '0',
          'recommend_city' : '1',
          // 'project_state' : '3'
        }
      }
			/* 分页
			* ========================================= */
			scope.maxSize = 5;             //最多显示多少个按钮
			scope.bigCurrentPage = 1;      //当前页码
			scope.itemsPerPage = 10         //每页显示几条
			scope.searchform = {};
			scope.getlist = function () {
				var para = {
					pageNo:scope.bigCurrentPage, 
					pageSize:scope.itemsPerPage,
				};
				para = angular.extend(params, para, scope.searchform);
				$resource(url, {}, {}).
				save(para,function(res) {
					console.log(para);
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					scope.objs = res.data.results;
					scope.bigTotalItems = res.data.totalRecord;

					
				})
			};

		scope.search = function(){
        var para = {
          pageNo:scope.bigCurrentPage, 
					pageSize:scope.itemsPerPage,
        };
        para = angular.extend(params, para);
        $resource('/api/as/ggc/reviewPlanning/findInfoList', {}, {}).
        save(para,function(res) {
            if (res.errcode !== 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log(res);
            console.log('上面是res');
            scope.objs = res.data.results;
            scope.bigTotalItems = res.data.totalRecord;
        })
    }

    scope.$watch('reviewflag', function(){
      scope.getlist();
    }, true)
    
		// 查看项目
    scope.toinfo = function(index){
        scope.item = scope.objs[index];
        var modalInstance = $modal.open({
          template: require('../views/projectinfofh.html'),
          controller: 'projectinfofh',
          size: 'lg',
          resolve: {
            items: function () {
              return scope.item;
            },
            type: function () {
              return scope.type;
            }
            
          }
        });
        modalInstance.result.then(function (showResult) {
          alert('复核驳回');
          scope.reviewflag++;	
          // scope.getlist();
        });
      }
      // 复核
      scope.rejectInfo= function (index) {
				console.log('尽力了')
				scope.item = scope.objs[index];
				var modalInstance = $modal.open({
					template: require('../views/reason.html'),
					controller: 'reason',
					size: 'lg',
					resolve: {
						items: function () {
							return scope.item;
            },
            type: function () {
							return scope.type;
						},
						flag: function () {
							return '11'
						}
					}
				});
				modalInstance.result.then(function (showResult) {
          scope.examineflag++;
				});
			}
    }
	}
}